﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using StuRecruitSysModels;



namespace StuRecruitSysDAL
{
    public class CashierService
    {
        private static string connString = "Data Source=.;Initial Catalog=StuRecruitDB;User ID=sa;Pwd=123";

        // 数据库连接 Connection 对象

        Cashier cashier = new Cashier();


        public Cashier GetCashierByUsername(string username)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = connString;
            // 查询用sql语句
            string sql = string.Format(
                "SELECT *  FROM  cashier  WHERE  username='{0}' ",username);
            SqlCommand command = new SqlCommand(sql,con);
            con.Open();
            SqlDataReader objReader = command.ExecuteReader(CommandBehavior.CloseConnection);
            try
            {
                if (objReader.Read())
                {
                    cashier.Cpwd = Convert.ToString(objReader["cpwd"]);
                    cuser.uname = username;
                }
                else
                {
                    cashier.Cpwd = "";
                }
            }
            finally
            {
                con.Close(); // 关闭数据库连接
            }
            return cashier;
        }
    }
  
}
